package Test;

import org.junit.Test;

public class Demo2 extends Thread{

    public Demo2(String name) {
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(getName() + " " + i);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        new Demo2("新线程").start();
        for (int i = 0; i < 100; i++) {
            if (i == 20){
                Demo2 jt  = new Demo2("被Join的线程");
                jt.start();
                jt.join();
            }
            System.out.println(Thread.currentThread().getName() + " " + i);
        }
    }
}
